import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Homepage from '../components/Homepage/Homepage'
import OrderManagement from '../components/OrderManagement/OrderManagement'
import Test from '../components/Test/Test'
// import BaseInfo from "../components/userRegister/BaseInfo";
import prestore from "../components/prestore/prestore";
import EnterpriseInfo from "../components/userRegister/EnterpriseInfo";
import TradingCenter from "@/components/tradingCenter/TradingCenter";
import SellerGoodsManagement from "@/components/sellerGoodsManagement/SellerGoodsManagement"
// import UserInfo from "../components/userRegister/UserInfo";
import RegisterIndex from "../components/userRegister/RegisterIndex";
import ReleaseNew from "../components/ReleaseNew/ReleaseNew";
import AuditNews from "../components/auditNews/AuditNews";
import PropSeller from "../components/tradingCenter/PropSeller";
import PropBuyer from "../components/tradingCenter/PropBuyer";
import PaySuccess from "../components/prestore/PaySuccess";
import Login from "../components/userLogin/Login";
import InformationCenter from "../components/informationCenter/informationCenter";
import MessageInform from "../components/messageInform/MessageInform";
import OrderPaySuccess from "../components/OrderManagement/OrderPaySuccess";
import AuditProp from "../components/auditProp/AuditProp";
import AuditRegister from "../components/AuditRegister/AuditRegister"
import Admin from "../components/admin/AdminManagement"
import UserInfoManage from "../components/userInfoManage/UserInfoManage"
import ls from  '../components/common/CommonJS.js'
Vue.use(Router);

 const router= new Router({
  routes: [
    {
      path: '/',
      //redirect 是重新定向
      redirect: '/login'
    },
    {
      path: '/Homepage',
      name: 'Homepage',//主页
      component: Homepage,
      children: [
        {
          path: '/Test',
          name: 'Test',
          component: Test
        },
        {
          path: '/HelloWorld',
          name: 'HelloWorld',
          component: HelloWorld
        },
        {
          path: '/OrderManagement',//订单管理
          name: 'OrderManagement',
          component: OrderManagement
        },
        {
          path: "/InformationCenter",//
          name: 'InformationCenter',
          component: InformationCenter
        },
        {
          path: '/sellerGoodsManagement/SellerGoodsManagement',//牌子管理
          name: 'SellerGoodsManagement',
          component: SellerGoodsManagement
        },
        {
          path: '/tradingCenter/TradingCenter',//交易中心
          name: 'TradingCenter',
          component: TradingCenter
        },
        {
          path: '/prestore',//保证金管理
          name: 'prestore',
          component: prestore
        },
        {
          path: '/messageInform',//保证金管理
          name: 'messageInform',
          component: MessageInform
        },
        {
          path: '/userInfoManage',//保证金管理
          name: 'userInfoManage',
          component: UserInfoManage
        }
      ]
    },
    {
      //买方摘牌
      path: '/PropBuyer',
      name: 'PropBuyer',
      component: PropBuyer
    },
    {
      //卖方挂牌
      path: '/PropSeller',
      name: 'PropSeller',
      component: PropSeller
    },
    {
      path: '/registerIndex',
      name: 'RegisterIndex',
      component: RegisterIndex
    },
    // { //已弃用
    //   path: '/register/userInfo',
    //   name: 'UserInfo',
    //   component: UserInfo,
    //   meta: {
    //     keepAlive: true
    //   }
    // },
    {
      path: '/ReleaseNew',//资讯编辑
      name: 'ReleaseNew',
      component: ReleaseNew
    },
    // { //已弃用
    //   path: '/register/enterpriseInfo',
    //   name: 'EnterpriseInfo',
    //   component: EnterpriseInfo
    // },



   {
      path: '/register/enterpriseInfo',//企业注册
      name: 'EnterpriseInfo',
      component: EnterpriseInfo
    },
    {      path: "/AuditNews",//资讯审核
      name: 'AuditNews',
      component: AuditNews
    },
    {
      path: '/login',
      name: 'Login',
      component: Login
    },

    {
      path: '/prestore',//资金管理
      name: 'prestore',
      component: prestore
    },
    {
      path: '/AuditRegister',//注册审核
      name: 'AuditRegister',
      component: AuditRegister
    },
    {
      path: '/AuditProp',//交易审核
      name: 'AuditProp',
      component: AuditProp
    },
    {
      path: '/Admin',//平台侧用户创建
      name: 'Admin',
      component: Admin
    }
    ,
    {
      path: '/PaySuccess',
      name: 'PaySuccess',
      component: PaySuccess
    },
    {
      path: '/OrderPaySuccess',
      name:'OrderPaySuccess',
      component: OrderPaySuccess
    },
    {
      path: '/messageInform',
      name: 'MessageInform',
      component: MessageInform
    },
    {
      path: '/AuditProp',
      name:'AuditProp',
      component: AuditProp
    },
    {
      path: '/AuditRegister',
      name:'AuditRegister',
      component: AuditRegister
    },
  ]
});

router.beforeEach((to, from, next) => {
  console.log("即将跳转",to.path);
  // next();
  // if(to.name=='RegisterIndex'){
  //   next();
  // }
  // if(to.name=='Login'){
  //   next();
  // }
  // 逻辑操作

  if(ls.getItem("userInfo")!=null){
    next();
    // NProgress.done();
  }else {
    if(to.path=='/login'||to.path=='/registerIndex'){
      next();
    }else {
      next("/login");
    }
    // NProgress.done();
  }


})
export  default router;

